home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1997 / HAM Radio 1997.iso / vcls / wsanet8a / wsanet / wfingerd / wfingerd.frm < prev    next >
Text File  |  1996-04-08  |  10KB  |  373 lines

  1. VERSION 2.00
  2. Begin Form Main 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "WFingerD - Finger Daemon"
  5.    ClientHeight    =   4620
  6.    ClientLeft      =   960
  7.    ClientTop       =   1680
  8.    ClientWidth     =   6090
  9.    FontBold        =   -1  'True
  10.    FontItalic      =   0   'False
  11.    FontName        =   "MS Sans Serif"
  12.    FontSize        =   9.75
  13.    FontStrikethru  =   0   'False
  14.    FontUnderline   =   0   'False
  15.    Height          =   5280
  16.    Icon            =   WFINGERD.FRX:0000
  17.    Left            =   915
  18.    LinkTopic       =   "Form1"
  19.    ScaleHeight     =   4620
  20.    ScaleWidth      =   6090
  21.    Top             =   1065
  22.    Width           =   6180
  23.    Begin CommandButton PanelFilename 
  24.       Caption         =   "PanelFilename"
  25.       Height          =   375
  26.       Left            =   120
  27.       TabIndex        =   5
  28.       Top             =   600
  29.       Width           =   5295
  30.    End
  31.    Begin SSPanel PanelLocalHost 
  32.       Align           =   1  'Align Top
  33.       Alignment       =   6  'Center - TOP
  34.       BackColor       =   &H00C0C0C0&
  35.       BevelWidth      =   2
  36.       Caption         =   "PanelLocalHost"
  37.       Font3D          =   4  'Inset w/heavy shading
  38.       Height          =   495
  39.       Left            =   0
  40.       TabIndex        =   4
  41.       Top             =   0
  42.       Width           =   6090
  43.       Begin Label LabelLocalAddr 
  44.          Alignment       =   2  'Center
  45.          BackColor       =   &H00C0C0C0&
  46.          Caption         =   "LabelLocalAddr"
  47.          FontBold        =   0   'False
  48.          FontItalic      =   0   'False
  49.          FontName        =   "MS Sans Serif"
  50.          FontSize        =   8.25
  51.          FontStrikethru  =   0   'False
  52.          FontUnderline   =   0   'False
  53.          Height          =   255
  54.          Left            =   0
  55.          TabIndex        =   3
  56.          Top             =   240
  57.          Width           =   6015
  58.       End
  59.    End
  60.    Begin CommonDialog CMDialog 
  61.       Left            =   5520
  62.       Top             =   3000
  63.    End
  64.    Begin Ini Ini 
  65.       Left            =   5520
  66.       Top             =   1320
  67.    End
  68.    Begin NetClient NetClient 
  69.       Left            =   5520
  70.       LineDelimiter   =   ""
  71.       RecvThreshold   =   0
  72.       RemoteService   =   ""
  73.       SendSize        =   8192
  74.       Top             =   1800
  75.    End
  76.    Begin SSPanel StatusBar 
  77.       Align           =   2  'Align Bottom
  78.       Alignment       =   1  'Left Justify - MIDDLE
  79.       AutoSize        =   3  'AutoSize Child To Panel
  80.       BackColor       =   &H00C0C0C0&
  81.       BevelInner      =   1  'Inset
  82.       BorderWidth     =   1
  83.       Caption         =   "Ok."
  84.       Font3D          =   3  'Inset w/light shading
  85.       Height          =   300
  86.       Left            =   0
  87.       TabIndex        =   0
  88.       Top             =   4320
  89.       Width           =   6090
  90.    End
  91.    Begin SSFrame FrameListHosts 
  92.       Caption         =   "Finger Clients"
  93.       Font3D          =   2  'Raised w/heavy shading
  94.       Height          =   3135
  95.       Left            =   120
  96.       ShadowStyle     =   1  'Raised
  97.       TabIndex        =   1
  98.       Top             =   1080
  99.       Width           =   5295
  100.       Begin ListBox ListHosts 
  101.          Height          =   2760
  102.          Left            =   120
  103.          TabIndex        =   2
  104.          Top             =   240
  105.          Width           =   5055
  106.       End
  107.    End
  108.    Begin NetServer NetServer 
  109.       Left            =   5520
  110.       QueueSize       =   0
  111.       Top             =   2400
  112.    End
  113.    Begin Menu MenuAbout 
  114.       Caption         =   "&About"
  115.    End
  116. End
  117. Option Explicit
  118.  
  119. Dim msFingerFile As String
  120. Dim miFile As Integer
  121. Dim mlLength As Long
  122.  
  123. Const OFN_FILEMUSTEXIST = &H1000&
  124. Const OFN_PATHMUSTEXIST = &H800&
  125. Const OFN_READONLY = &H1&
  126.  
  127. Const MAX_SIZE = 16384
  128. Const CHUNK_SIZE = 8192
  129.  
  130. Sub Form_Load ()
  131.     
  132.     On Error Resume Next
  133.  
  134.     'Ctl3d_Load
  135.  
  136.     PanelLocalHost = NetClient.HostName
  137.     LabelLocalAddr = NetClient.HostAddr
  138.     
  139.     If PanelLocalHost = "" Then
  140.         PanelLocalHost = "LocalHost"
  141.         LabelLocalAddr = "unknown address"
  142.     End If
  143.  
  144.     NetServer.LocalService = "finger"
  145.     If NetServer.LocalService = "" Then
  146.         NetServer.LocalPort = 79
  147.     End If
  148.  
  149.     NetClient.RecvSize = MAX_SIZE
  150.     NetClient.SendSize = MAX_SIZE
  151.  
  152.     NetServer.Listen = True
  153.  
  154.     ListHosts.Clear
  155.  
  156.     ' Read our .INI file for a default msFingerFile
  157.     Ini.Default = ""
  158.     Ini.Filename = "wfingerd.ini"
  159.     Ini.Section = "Configuration"
  160.     Ini.Entry = "FingerFile"
  161.     If Ini.Value = "" Then
  162.         Ini.Value = ""
  163.         msFingerFile = ""
  164.     Else
  165.         msFingerFile = Ini.Value
  166.     End If
  167.         
  168.     PanelFilename.Caption = msFingerFile
  169.     
  170.     Ini.Section = "Windows"
  171.     Main.Top = gfMISCIniGetInt("Main.Top", (Main.Top))
  172.     Main.Left = gfMISCIniGetInt("Main.Left", (Main.Left))
  173.     Main.Width = gfMISCIniGetInt("Main.Width", (Main.Width))
  174.     Main.Height = gfMISCIniGetInt("Main.Height", (Main.Height))
  175.  
  176. End Sub
  177.  
  178. Sub Form_QueryUnload (Cancel As Integer, UnloadMode As Integer)
  179.  
  180.     If UnloadMode = 0 Then
  181.         Ini.Section = "Windows"
  182.         gsMISCIniPutInt "Main.Top", (Main.Top)
  183.         gsMISCIniPutInt "Main.Left", (Main.Left)
  184.         gsMISCIniPutInt "Main.Width", (Main.Width)
  185.         gsMISCIniPutInt "Main.Height", (Main.Height)
  186.     End If
  187.  
  188. End Sub
  189.  
  190. Sub Form_Resize ()
  191.  
  192.     If Main.WindowState = 1 Then Exit Sub
  193.  
  194.     LabelLocalAddr.Width = ScaleWidth
  195.  
  196.     PanelFilename.Width = Abs(ScaleWidth - 240)
  197.  
  198.     FrameListHosts.Width = Abs(ScaleWidth - 240)
  199.     FrameListHosts.Height = Abs(ScaleHeight - FrameListHosts.Top - StatusBar.Height - 120)
  200.     
  201.     ListHosts.Width = Abs(FrameListHosts.Width - 240)
  202.     ListHosts.Height = Abs(FrameListHosts.Height - 360)
  203.  
  204. End Sub
  205.  
  206. Sub Form_Unload (Cancel As Integer)
  207.     
  208.     NetServer.Listen = False
  209.     
  210.     'Ctl3d_UnLoad
  211.  
  212. End Sub
  213.  
  214. Sub MenuAbout_Click ()
  215.  
  216.     gsMISCAboutLoad "About WFingerD", "WFingerD v1.1", "This daemon application services TCP Finger clients (typically port 79). You can select any file you wish to be your machine's finger response."
  217.  
  218. End Sub
  219.  
  220. Sub NetClient_OnError (iErrorNumber As Integer)
  221.     
  222.     StatusBar = NetClient.ErrorMessage
  223.     
  224.     Debug.Print "NetClient:" & NetClient.ErrorMessage
  225.  
  226.     Close #miFile
  227.     NetClient.Connect = False
  228.  
  229. End Sub
  230.  
  231. Sub NetClient_OnRecv ()
  232. Dim sTemp As String
  233. Dim iPlace As Integer
  234.  
  235.     On Error GoTo ErrorHandler
  236.  
  237.     If NetClient.RecvCount = 0 Then Exit Sub
  238.     sTemp = NetClient
  239.  
  240.     While Right$(sTemp, 1) = Chr$(13) Or Right$(sTemp, 1) = Chr$(10)
  241.         sTemp = Left$(sTemp, Len(sTemp) - 1)
  242.     Wend
  243.  
  244.     NetClient.SendThreshold = 1
  245.     ListHosts.AddItem NetClient.HostName & "(" & NetClient.HostAddr & ")" & Chr$(9) & Str$(NetClient.RemotePort) & Chr$(9) & sTemp
  246.  
  247.     If msFingerFile = "" Then
  248.         NetClient = "Oops, I've forgotten what I'm supposed to tell you... Try again later!"
  249.         NetClient.Connect = False
  250.         Exit Sub
  251.     End If
  252.         
  253.     miFile = FreeFile
  254.     Open msFingerFile For Input As #miFile
  255.     
  256.     mlLength = LOF(miFile) - 1
  257.     
  258.     SendFingerFile
  259.  
  260.     Exit Sub
  261.  
  262. ErrorHandler:
  263.     Select Case Err
  264.         Case 62:
  265.             Resume Next
  266.         Case 53:
  267.             NetClient = "Tell my owner that his WFingerD file is missing!" & Chr$(13) & Chr$(10)
  268.             NetClient.Connect = False
  269.             Exit Sub
  270.     End Select
  271.     NetClient = Chr$(13) & Chr$(10) & "Oops, Tell my owner that I had an error" & Str$(Err) & " (" & Error$(Err) & ") on line " & Str$(Erl) & " in WFingerD. Thanks!" & Chr$(13) & Chr$(10)
  272.     If miFile <> 0 Then Close #miFile
  273.     NetClient.Connect = False
  274.     Exit Sub
  275.  
  276. End Sub
  277.  
  278. Sub NetClient_OnSend ()
  279. Dim sTemp As String
  280.  
  281.     SendFingerFile
  282.  
  283. End Sub
  284.  
  285. Sub NetServer_OnAccept (Socket As Integer, PeerAddr As String, RemotePort As Integer)
  286.     
  287.     On Error Resume Next
  288.  
  289.     If NetClient.Connect = True Then
  290.         Socket = 0
  291.         Exit Sub
  292.     End If
  293.  
  294.     NetClient.Socket = Socket
  295.     
  296.     NetClient.Debug = True
  297.  
  298. End Sub
  299.  
  300. Sub NetServer_OnError (iErrorNumber As Integer)
  301.  
  302.     StatusBar = NetServer.ErrorMessage
  303.     
  304.     Debug.Print "NetServer:" & NetServer.ErrorMessage
  305.  
  306. End Sub
  307.  
  308. Sub PanelFilename_Click ()
  309.  
  310.     On Error Resume Next
  311.  
  312.     CMDialog.CancelError = True
  313.     CMDialog.DefaultExt = ".txt"
  314.     CMDialog.DialogTitle = "WFingerD - Load Finger info"
  315.     CMDialog.Filename = msFingerFile
  316.     CMDialog.Filter = "Text (*.txt)|*.txt|Everything (*.*)|*.*"
  317.     CMDialog.FilterIndex = 1
  318.     CMDialog.Flags = OFN_FILEMUSTEXIST Or OFN_PATHMUSTEXIST Or OFN_READONLY
  319.     CMDialog.Action = 1
  320.     
  321.     If Err <> 32755 Then
  322.        
  323.        msFingerFile = CMDialog.Filename
  324.        PanelFilename.Caption = msFingerFile
  325.        
  326.        Ini.Filename = "wfingerd.ini"
  327.        Ini.Section = "Configuration"
  328.        Ini.Entry = "FingerFile"
  329.        Ini.Value = msFingerFile
  330.  
  331.     End If
  332.         
  333. End Sub
  334.  
  335. Sub SendFingerFile ()
  336. Dim sTemp As String
  337.  
  338.     On Error GoTo ErrorHandler2
  339.  
  340.     If Not EOF(miFile) Then
  341.         If mlLength > CHUNK_SIZE Then
  342.             sTemp = Input$(CHUNK_SIZE, miFile)
  343.             NetClient = sTemp
  344.             mlLength = mlLength - CHUNK_SIZE
  345.         Else
  346.             sTemp = Input$(mlLength, miFile)
  347.             If sTemp = "" Then
  348.                 Close #miFile
  349.                 NetClient.Connect = False
  350.                 Exit Sub
  351.             End If
  352.             NetClient = sTemp
  353.         End If
  354.     Else
  355.         Close #miFile
  356.         NetClient.Connect = False
  357.     End If
  358.  
  359.     Exit Sub
  360.  
  361. ErrorHandler2:
  362.     Select Case Err
  363.         Case 62:
  364.             Resume Next
  365.     End Select
  366.     NetClient = Chr$(13) + Chr$(10) + "Oops, Tell my owner that I had an error" + Str$(Err) + " (" + Error$(Err) + ") on line " + Str$(Erl) + " in WFingerD. Thanks!" + Chr$(13) + Chr$(10)
  367.     If miFile <> 0 Then Close #miFile
  368.     NetClient.Connect = False
  369.     Exit Sub
  370.  
  371. End Sub
  372.  
  373.